package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TravelOrder;
import com.ruoyi.system.service.ITravelOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行程单模块Controller
 * 
 * @author 宋一鸣
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/system/order")
public class TravelOrderController extends BaseController
{
    @Autowired
    private ITravelOrderService travelOrderService;

    /**
     * 查询行程单模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TravelOrder travelOrder)
    {
        startPage();
        List<TravelOrder> list = travelOrderService.selectTravelOrderList(travelOrder);
        return getDataTable(list);
    }

    /**
     * 导出行程单模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "行程单模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelOrder travelOrder)
    {
        List<TravelOrder> list = travelOrderService.selectTravelOrderList(travelOrder);
        ExcelUtil<TravelOrder> util = new ExcelUtil<TravelOrder>(TravelOrder.class);
        util.exportExcel(response, list, "行程单模块数据");
    }

    /**
     * 获取行程单模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(travelOrderService.selectTravelOrderById(id));
    }

    /**
     * 新增行程单模块
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "行程单模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelOrder travelOrder)
    {
        return toAjax(travelOrderService.insertTravelOrder(travelOrder));
    }

    /**
     * 修改行程单模块
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "行程单模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelOrder travelOrder)
    {
        return toAjax(travelOrderService.updateTravelOrder(travelOrder));
    }

    /**
     * 删除行程单模块
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "行程单模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(travelOrderService.deleteTravelOrderByIds(ids));
    }
}
